All Questions
1,196 questions
-3votes
1answer
46views
How to make percent chance that there will be a * in a 2D array decrease
My result I need to make the number of stars decrease with each line, but I have no idea how. import random import numpy as np import sys size = int(sys.argv[1]) mat = np.full((size, size), '\x1b[35m....
-3votes
1answer
67views
Why can't I stack 3D arrays with np.concatenate in numpy, while 1D and 2D arrays work?
I'm working with 3D numpy arrays and having trouble stacking two of them. Here’s what I’m trying to do: import numpy as np grid = np.arange(16).reshape((1, 4, 4)) grid2 = grid[:, :-1, ::-1].copy() I ...
0votes
0answers
23views
Xarray .where() unable to parse multiple n-dimensional arrays
I'm trying to use the xr.where() function to create a binary based on multiple arrays. The code I am using is the following: binary = xr.where((snd_nc.SNOWDP >= 0.2) & (tas_nc.tas <= 0) &...
1vote
1answer
87views
How do I effectively compute pairwise quantities in numpy?
I want to compute pairwise quantities, e.g. distances between two points. A simple example would be import numpy as np N = 9 x = np.linspace(0,1,N) y = np.abs(x - x[:,None]) # pairwise 1d eucdlidian ...
1vote
1answer
111views
algorithm to detect pools of 0s in a matrix
I'm writing an algorithm that detects regions of contiguous empty cells that are completely surrounded (orthogonally) by filled cells and do not extend to the edge of the grid. Let's call such regions ...
-3votes
1answer
103views
How to Slice Multi Dimensional Array?
Dipping my toes into multi dimensional array slicing in Python and am hitting a wall of confusion with the following code # Example 2D array matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] # ...
1vote
2answers
740views
ValueError: could not broadcast input array from shape A into shape B
I used Python with Numpy to create an array filled with numbers from a tuple, and set it up to be a 4x4 matrix. numbers = (-8, -3, -5, 0, 4, 5, 6, 10, 7,8, 9, 100, 10, 11, 12, 1000) numbers_array = ...
0votes
1answer
41views
Why are my numpy array elements being cast to lists?
import numpy as np ar1 = np.array([[[1,2,3],[4,5,6]],[[1,2,3],[4,5,6]]]) ar2 = np.array([[[1,2,3],[4,5,6]],[[1,2,3,4],[4,5,6,7]]]) print(ar1) print(ar2) When I run this the second array prints out ...
3votes
2answers
157views
Numpy array methods are faster than numpy functions?
I have to work with the learning history of a Keras model. This is a basic task, but I've measured the performance of the Python built-in min() function, the numpy.min() function, and the numpy ...
1vote
1answer
72views
Is there a way to efficiently construct a 3d array from symmetric submatrices of a 2d array according to an array of different index sets?
I have a two-dimensional array A, and another two-dimensional array I where each row corresponds to a set of indices with which I want to extract symmetric two-dimensional subarrays from A. I want to ...
0votes
2answers
95views
How can I multidimensionalise this code that finds indices from a list of values?
I have some code that finds the indices of elements in the "input" list that match any element in the "values" list. The indices are then outputted, arranged in the same order as ...
-1votes
1answer
93views
Manipulating a 3d array in python
I have an array called result that has a shape of (1200,67,67). Along the axis with length 1200 the array is correct. However, the other two axis have been flipped. I am getting: result[0,:,:] = array(...
1vote
1answer
728views
Difference between "size" and "itemsize" in Numpy
I have been studying for numpy library in python. I used the code import numpy as np arr=np.array([(11,12,13),(17,18,19)]) arr.size and it's output is 6 That is right but when I run import numpy as ...
1vote
1answer
241views
Saving multidimensional numpy array from pandas cell into Excel
I would like to save a multidimensional numpy array which is stored in a Pandas cell into an Excel file. But Excel converts the array into a string. My pandas Dataframe looks like that: df_data ...
0votes
0answers
49views
Chunking up a 3D array with periodic boundary conditions into subarrays
I have a 3D numpy array of shape [N,N,N]. I want to split it into subcubes of size [n,n,n] and store them in an array of shape [N_subcubes, n, n, n, 1]. I also would like each subcube to overlap the ...